from subprocess import call
from colorama import init, Fore
from pick import pick
from main import phone_check, adb_terminate

init(autoreset=True)


def user_menu():
    try:
        title = (
            f"Choose your option:\n"
            f"Or tap \"Q\" key for exit\n"
            f"-------------------------"
        )
        options = [
            "To execute commands manually",
            "To uninstall apps manually",
            "To uninstall apps via list_to_remove.txt",
            "To reinstall deleted apps",
            "To enable disabled apps",
        ]
        option, index = pick(options, title, indicator="> ")
        match index:
            case 0:
                with open("work_directory.ini", mode="r", encoding="UTF-8") as wd_ini_file:
                    work_directory = wd_ini_file.readline().strip()
                    work_directory = work_directory.replace("\\", "/")
                phone_check()
                print(
                    f"To finish enter: " + Fore.RED + "exit\n",
                    f"-------------------------"
                )
                call([work_directory, "shell"])
            case 1:
                import uninstall
            case 2:
                import list_remover
            case 3:
                import reinstall
            case 4:
                import disabled
    except TypeError:
        print(
            f"{Fore.RED}\"Q\" key was tapped!\n"
            f"{Fore.RED}Script is closed!"
        )
        adb_terminate()
